﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UserManage.aspx.cs" Inherits="UserManage"
    EnableEventValidation="false" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="css/style.css" type="text/css" rel="Stylesheet" />
</head>
<body>
    <form id="form1" runat="server">

    <script type="text/javascript">
        function ReceiveServerData(arg, context) {
            //Label1.innerText = "-- " + arg;
            var preName = '<%=preName%>';
            var cmd = arg.split(',');

            if (cmd.length == 1) {
                alert(arg);
                return;
            }

            if (cmd[0] == "delete") {
                if (cmd[1] == "") return;
                var row = document.getElementById(preName + cmd[1]);
                row.innerText = "";
            }

            if (cmd[2] == "") return;

            if (cmd[0] == "save" && cmd[1] == "" || cmd[0] == "add") { //新增
                {
                    var tb = document.getElementById(preName + 'tbUser');
                    var r = tb.insertRow(tb.rows.length);
                    r.id = preName + cmd[2];
                    var c = r.insertCell(0);

                    c.valign = "middle";
                    c.align = "middle";
                    //c.style="width:30% height:20"
                    c.innerText = "·";
                    c = r.insertCell(1);
                    c.id = preName + cmd[2] + "1";
                    c.innerHTML = "<a href=\"#\" onClick='displaydetail(\"" + cmd[2] + "\",\"" + cmd[3] + "\",\"" + cmd[4] + "\",\"" + cmd[5] + "\")'>" + cmd[2] + "</a>&nbsp;";

                    c = r.insertCell(2);
                    c.id = preName + cmd[2] + "2";
                    c.innerHTML = "<a href=\"#\" onClick='displaydetail(\"" + cmd[2] + "\",\"" + cmd[3] + "\",\"" + cmd[4] + "\",\"" + cmd[5] + "\")'>" + cmd[4] + "</a>&nbsp;";
                }
            }

            if (cmd[0] == "save" && cmd[1] != "") {
                var r = document.getElementById(preName + cmd[1]);
                r.id = preName + cmd[2];

                var c = document.getElementById(preName + cmd[1] + "1");
                c.id = preName + cmd[2] + "1";
                c.innerHTML = "<a href=\"#\" onClick='displaydetail(\"" + cmd[2] + "\",\"" + cmd[3] + "\",\"" + cmd[4] + "\",\"" + cmd[5] + "\")'>" + cmd[2] + "</a>&nbsp;";

                c = document.getElementById(preName + cmd[1] + "2");
                c.id = preName + cmd[2] + "2";
                c.innerHTML = "<a href=\"#\" onClick='displaydetail(\"" + cmd[2] + "\",\"" + cmd[3] + "\",\"" + cmd[4] + "\",\"" + cmd[5] + "\")'>" + cmd[4] + "</a>&nbsp;";
            }
            (document.getElementById(preName + "TextBox1")).value = "";
            (document.getElementById(preName + "TextBox2")).value = "";
            (document.getElementById(preName + "TextBox3")).value = "";
            //(document.getElementById(preName+"TextBox4")).value = "";
            (document.getElementById(preName + "TextBox1")).title = "";
        }
        function ProcessCallBackError(arg, context) {
            Message.innerText = 'An error has occurred.';
        }

        function displaydetail(name, pass, type, path) {
            var preName = '<%=preName%>';
            var ed = document.getElementById(preName + "TextBox1");
            ed.value = name;
            ed.title = name;
            var ed = document.getElementById(preName + "TextBox2");
            ed.value = pass;
            var ed = document.getElementById(preName + "TextBox3");
            ed.value = path;
            //        var ed = document.getElementById(preName+"TextBox4");
            //        ed.value = path;

            var ed = document.getElementById(preName + "DropDownList1");

            //ed.item(ed.selectedIndex).text=type;
            if (type == '管理员') {
                ed.selectedIndex = 0;
            }
            else {
                ed.selectedIndex = 1;
            }
        }

        function callserver(cmd) {
            var preName = '<%=preName%>';
            if (cmd == 'delete') {
                var ed = document.getElementById(preName + 'TextBox1');
                var id = ed.title;
                CallTheServer('delete,' + id, null);
            }
            if (cmd == 'save') {
                var ed1 = document.getElementById(preName + 'TextBox1');
                var id = ed1.title;
                var ed2 = document.getElementById(preName + 'TextBox2');
                var ed3 = document.getElementById(preName + 'TextBox3');
                var atype = document.getElementById(preName + 'DropDownList1');

                //var ed4=document.getElementById(preName+'TextBox4');
                CallTheServer('save,' + id + ',' + ed1.value + ',' + ed2.value + ',' + atype.item(atype.selectedIndex).text + ',' + ed3.value + ',', null);
            }
            if (cmd == 'add') {
                var ed1 = document.getElementById(preName + 'TextBox1');
                var ed2 = document.getElementById(preName + 'TextBox2');
                var ed3 = document.getElementById(preName + 'TextBox3');
                var atype = document.getElementById(preName + 'DropDownList1');
                //var ed4=document.getElementById(preName+'TextBox4');
                CallTheServer('add,,' + ed1.value + ',' + ed2.value + ',' + atype.item(atype.selectedIndex).text + ',' + ed3.value + ',', null);
            }
        }
    </script>

    <div>
        &nbsp;
        <asp:Table ID="tbUser" runat="server">
        </asp:Table>
        <table style="width: 501px">
            <tr>
                <td style="width: 723px; height: 52px" valign="top">
                    &nbsp;
                    <table>
                        <tr>
                            <td align="right">
                                账号名
                            </td>
                            <td>
                                <asp:TextBox ID="TextBox1" runat="server" Width="87px"></asp:TextBox>
                            </td>
                            <td align="right">
                                密码
                            </td>
                            <td>
                                <asp:TextBox ID="TextBox2" runat="server" Width="67px"></asp:TextBox>
                            </td>
                            <td>
                                用户名
                            </td>
                            <td>
                                <asp:TextBox ID="TextBox3" runat="server" Width="87px"></asp:TextBox>
                            </td>
                            <td align="right">
                                类型
                            </td>
                            <td>
                                <asp:DropDownList ID="DropDownList1" runat="server">
                                    <asp:ListItem>管理员</asp:ListItem>
                                    <asp:ListItem>普通用户</asp:ListItem>
                                </asp:DropDownList>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td style="width: 723px;" valign="top" align="center">
                    <asp:TextBox ID="TextBox" runat="server" Width="81px" Visible="False"></asp:TextBox>&nbsp;
                    &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                    &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
                </td>
            </tr>
            <tr>
                <td style="width: 723px; height: 50px;" align="right" valign="top">
                    &nbsp;<input type="button" id="btnDel" runat="server" value="删除" onclick="callserver('delete')" />
                    &nbsp; &nbsp;
                    <input type="button" id="btnAdd" runat="server" value="新增" onclick="callserver('add')" />&nbsp;
                    &nbsp;<input type="button" id="btnSave" runat="server" value="保存" onclick="callserver('save')" />
                </td>
            </tr>
        </table>
    </div>
    <div>
        <asp:Label ID="Label1" runat="server" />
    </div>
    </form>
</body>
</html>
